<template>
  <!-- 客户聊天详情 -->
  <div class="chat_box">
    <!-- 客户信息 -->
    <div class="chat_box_item chat_cus">
      <div class="border_bom flex_between">
        <div style="padding: 20px 0">客户信息</div>

        <el-button @click="$emit('send')">返回</el-button>
      </div>
      <!-- 客户详细信息 -->
      <div class="cus_info">
        <!-- 诊所 -->
        <div class="flex_y_center">
          <div>诊所：</div>
          <div>青岛敦化路诊所</div>
        </div>
        <!-- 客户姓名 -->
        <div class="flex_y_center">
          <div>客户姓名：</div>
          <div>张三</div>
        </div>
        <!-- 年龄 -->
        <div class="flex_y_center">
          <div>年龄：</div>
          <div>20</div>
        </div>
        <!-- 联系方式 -->
        <div class="flex_y_center">
          <div>联系方式：</div>
          <div>12345678901</div>
        </div>
        <!-- 地址 -->
        <div class="flex_y_center">
          <div>地址：</div>
          <div>xx省xx市xx路xx号</div>
        </div>
      </div>
    </div>
    <div class="line"></div>
    <!-- 聊天记录 -->
    <div class="chat_box_item chat_info_box">
      <div class="border_bom" style="padding: 20px 0">聊天信息</div>
      <div id="test" v-loading="infoLoad" class="chat_info">
        <!-- 聊天记录的每一项 -->
        <div
          v-for="(item, index) of chatRecord"
          :key="index"
          :class="{ text_right: item.id == 1 }"
          style="margin-bottom: 10px; display: flex"
        >
          <div class="flex_y_center">
            <img v-show="item.id == 2" class="user_avater" :src="item.avater" />
            {{ item.text }}
            <img v-show="item.id == 1" class="user_avater" :src="item.avater" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        infoLoad: false,

        // 存放聊天记录
        chatRecord: [],
      }
    },
    created() {
      this.getChatInfo()
    },
    methods: {
      // 获取聊天信息列表
      getChatInfo() {
        this.infoLoad = true

        setTimeout(() => {
          this.infoLoad = false
          this.chatRecord = [
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '我怎么知道你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你好好猜猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是。。。。。。。。。。。。。',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '我怎么知道你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你好好猜猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是。。。。。。。。。。。。。',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '我怎么知道你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你好好猜猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是。。。。。。。。。。。。。',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '我怎么知道你是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/2154076f950050ca.jpg',
              id: 2,
              text: '你好好猜猜我是谁',
            },
            {
              avater: 'https://s3.bmp.ovh/imgs/2022/03/b9c67dd9c1bba2d4.png',
              id: 1,
              text: '你是。。。。。。。。。。。。。',
            },
          ]
          this.$nextTick(() => {
            // 获取要操作的标签
            var ele = document.getElementById('test')
            //判断元素是否出现了滚动条
            if (ele.scrollHeight > ele.clientHeight) {
              //设置滚动条到最底部
              ele.scrollTop = ele.scrollHeight
            }
          })
        }, 3000)
      },
    },
  }
</script>

<style scoped>
  .flex_between {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .line {
    width: 1px;
    background-color: rgba(0, 0, 0, 0.1);
  }
  .border_bom {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  }
  .text_right {
    justify-content: flex-end;
    /* text-align: right; */
  }

  .chat_box {
    height: 65vh;
    display: flex;
  }
  .chat_box > .chat_box_item {
    display: flex;
    flex-direction: column;
  }
  .chat_cus {
    width: 35%;
    padding-right: 20px;
  }
  .chat_info_box {
    width: 65%;
    padding-left: 20px;
  }
  .cus_info,
  .chat_info {
    flex-grow: 1;
    margin-top: 20px;
  }
  .chat_info {
    padding: 15px 10px;
    border-radius: 5px;
    box-sizing: border-box;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.1);
  }
  .cus_info > div {
    margin-bottom: 10px;
  }
  .user_avater {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0 5px;
  }
</style>
